<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of model
 *
 * @author abc
 */

namespace application\kontakty;

class pridatmodel {

    private $database = false;

    public function __construct() {
        $this->database = new \system\database('mysql');
    }

    public function webname() {
        return \system\config::getConfig('webname');
    }

    public function info() {

        return 'Dnes je: ' . date('j. n. Y', time()) . ' | Přihlášen jako: ' . \system\session::get('username');
    }

    public function footer() {
        return 'powered by:<br><strong>php | mysql | html | css</strong>';
    }

    public function sidebar() {
        return '';
    }

    public function addkontakt($temppost, $appparams) {
        if (isset($appparams['ulozit']) == true) :
            $this->database->query('INSERT INTO contacts (contactname, phone, email, other) VALUES (:contactname, :phone, :email, :other)');
            $this->database->bind(':contactname', $temppost['jmenofield']);
            $this->database->bind(':phone', $temppost['phonefield']);
            $this->database->bind(':email', $temppost['emailfield']);
            $this->database->bind(':other', $temppost['textfield']);
            $this->database->execute();
            unset($_POST);
            header('Location: '.WWW_PATH.'/kontakty/pridat');
        endif;
    }

//    public function contents($app, $appaction, $appparams) {
//        if ($app == 'kontakty') :
//            $this->database->query('SELECT * FROM contacts ORDER BY id DESC');
//            $rows = $this->database->resultset();
//            dump($rows);
//        else :
//            throw new \Exception('Nemáte oprávnění prohlížet data!', 763);
//        endif;
//
//        return $rows;
//    }
//
//    public function existuser($postusername) {
//        $this->database->query('SELECT username FROM users WHERE username = :username LIMIT 1');
//        $this->database->bind(':username', $postusername);
//        $row = $this->database->single();
//
//        if ($row['username'] == $postusername) : return true;
//        else : return false;
//        endif;
//    }
//
//    public function loggeduser($postusername) {
//        $username = \system\session::get('username');
//        $logged = \system\session::get('logged');
//        $safety = \system\session::get('safety');
//
//        if ($username == $postusername AND $logged == true AND $safety == true) : return true;
//        else : return false;
//        endif;
//    }

}
